#!/bin/bash


if [ $# -eq 0 ]; then
	echo "  -s     run tests that contain match expressions that are exhaustive, disjoint and reachable"
	echo "  -ne    run tests that contain some match expressions that have missing patterns"
	echo "  -nd    run tests that contain some match expressions with overlapping patterns"
    echo "  -u     run tests that contain some match expressions with unreachable patterns"
    echo "  -w     run tests that contain wrong specification"
    echo "  -all   run all tests"
    echo "  -paper run tests described in the paper"
    exit 0	
fi

option=$1
matcheckoptions=${@:2:$#}


case "$option" in
        "-s")
          files=`find benchs/1.exhaustive_disjoint_reachable -name "*.scala" -type f`
          ;;
        "-ne")
          files=`find benchs/2.exhaustiveness_fails -name "*.scala" -type f`
          ;;
    	"-nd")
    	  files=`find benchs/3.disjointness_fails -name "*.scala" -type f`  
          ;;
        "-u")
          files=`find benchs/4.reachability_fails -name "*.scala" -type f`
          ;;
        "-w")
          files=`find benchs/5.wrong_specification -name "*.scala" -type f`
          ;;
       "-paper")
          files=`find benchs/0.paper -name "*.scala" -type f`
          ;;
        "-all")
          files=`find benchs -name "*.scala" -type f` 
          matcheckoptions=$*
          ;;
        "?")
          echo "don't know what to do with option $option"
          exit 1
          ;;
        ":")
          exit 1 
          ;;
        *)
        # Should not occur
          echo "Unknown error while processing options"
          exit 1
          ;;
esac



for file in $files
do
  echo "testing file " $file
  scala -cp build/ ch.epfl.lara.matcheck.matcheck config.conf $file $matcheckoptions 
  echo 
done
